<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增用户')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
    <form id="form-user-add" class="form-horizontal">
        <h4 class="form-header h4">基本信息</h4>
        <h1 class="form-header h1">注意：此处新增为【强制】调整，不涉及到现金变动。如果直接新增的话，相当于凭空增加了一个资产，使用时要慎重，注意备份数据库文件。
            <h1 class="form-header h1">
                如果是需要购入新的资产，填写[基金名称和基金类型]，[资产数量、成本总价、成本单价]都写为0，[历史收入可以按实际填]，再进行资产交易操作购买。</h1>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">基金名称：</label>
                        <div class="col-sm-8">
                            <input name="assetName" placeholder="请输入基金名称" class="form-control" type="text"
                                   required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label is-required">基金类型：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <select name="typeName" class="form-control m-b" required>
                                    <option value="股票基金">股票基金</option>
                                    <option value="债券基金">债券基金</option>
                                    <option value="固定收益">固定收益</option>
                                    <option value="货币基金">货币基金</option>
                                    <option value="股票">股票</option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">基金数量：</label>
                        <div class="col-sm-8">
                            <input id="numberOf" name="numberOf" placeholder="请输入基金数量" class="form-control"
                                   type="number" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">成本总价：</label>
                        <div class="col-sm-8">
                            <input id="costOf" name="costOf" placeholder="请输入当前价" class="form-control"
                                   type="number" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label is-required">成本单价：</label>
                        <div class="col-sm-8">
                            <input id="costPrice" name="costPrice"
                                   placeholder="请输入成本单价，这个是根据成本总价和数量算的。" class="form-control"
                                   type="number" required>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">历史收入：</label>
                        <div class="col-sm-8">
                            <input id="historyEarnings" name="historyEarnings" placeholder="历史收入没有就填0"
                                   class="form-control" type="number" required>
                        </div>
                    </div>
                </div>
            </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
    var prefix = ctx + "finance/asset";

    $("#form-user-add").validate({
        onkeyup: false,
        rules: {
            phonenumber: {
                isPhone: true,
                remote: {
                    url: prefix + "/checkPhoneUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "phonenumber": function () {
                            return $.common.trim($("#phonenumber").val());
                        }
                    }
                }
            },
        },
        messages: {
            "loginName": {
                remote: "用户已经存在"
            },
            "email": {
                remote: "Email已经存在"
            },
            "phonenumber": {
                remote: "手机号码已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var data = $("#form-user-add").serializeArray();
            $.operate.saveTab(prefix + "/add", data);
        }
    }

    /* 用户管理-新增-选择部门树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    $(function () {
        $('#post').select2({
            placeholder: "请选择岗位",
            allowClear: true
        });
    })
</script>
</body>
</html>